import oss2
import logging

from django.conf import settings
from oss2.exceptions import ClientError

auth = oss2.AuthV4(settings.OSS_CONFIG['access_key_id'], settings.OSS_CONFIG['access_key_secret'])

region = "cn-beijing"

logger = logging.getLogger('AchieveHandler')

def delete_from_oss(src, bucket_name):
    try:
        bucket = oss2.Bucket(auth, settings.OSS_CONFIG['endpoint'], bucket_name, region=region)
        bucket.delete_object(src)
    except ClientError as ce:
        logger.error("oss异常", exc_info=ce)